var douban_invite_helper = {
	init: function() {
		var block = '<div><h2>邀请助手   · · · · · ·  </h2>' +
			'<p class="pl2">' +
			        '> <a href="javascript:void(0);" id="people_selected_all">用户全选</a>' +
			'</p>' +
			'<p class="pl2">' +
			        '> <a href="javascript:void(0);" id="people_unselected_all">用户全不选</a>' +
			'</p>' +
		'</div>';
	
		var aside = this.getElementsByClassName('aside')[0];
		aside.innerHTML += block;
		
		
		document.getElementById('people_selected_all').addEventListener('click', function(){
			var inputs = document.getElementsByTagName('input');
			for (var i = 0; (input = inputs[i]) != null; i++) {
				if (input.type == 'checkbox') {
					inputs[i].checked = true;
				}
			}
		}, true);
		
		
		document.getElementById('people_unselected_all').addEventListener('click', function(){
			var inputs = document.getElementsByTagName('input');
			for (var i = 0; (input = inputs[i]) != null; i++) {
				if (input.type == 'checkbox') {
					inputs[i].checked = false;
				}
			}
		}, true);
		
	},
	
	getElementsByClassName: function(className) {
		var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
		var allElements = document.getElementsByTagName("*");
		var results = [];

		var element;
		for (var i = 0; (element = allElements[i]) != null; i++) {
			var elementClass = element.className;
			if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
				results.push(element);
		}

		return results;
	}
};

douban_invite_helper.init();